package com.patterns.proxy.commonDynamicProxy.proxy;

import com.patterns.proxy.commonDynamicProxy.subject.Subject;

import java.lang.reflect.InvocationHandler;

/**
 * Created by Xiao Yiyun on 2017/4/24.
 * 具体业务的动态代理
 */
public class SubjectDynamicProxy extends DynamicProxy {
    public static <T> T newProxyInstance(Subject subject) {
        //获得ClassLoader
        ClassLoader loader = subject.getClass().getClassLoader();
        //获得接口数组
        Class<?>[] classes = subject.getClass().getInterfaces();
        //获得handler
        InvocationHandler handler = new MyInvocationHandler(subject);
        return newProxyInstance(loader, classes, handler);
    }
}
